package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.baiwei.BaiweiScore;
import com.ucredit.babel.common.model.baiwei.BaiweiScoreRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 百维信用分
 * @author rrz
 *
 */
public class BaiweiScoreParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     *
     *百维信用分
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BaiweiScoreRecord obj= (BaiweiScoreRecord)model;
        BaiweiScore score = obj.getScore();

        StringBuilder sb = getBaseInfo(obj, successful);

        //信息 msg
        sb.append(score.getMsg()).append(CRT001);
        //错误码 code
        sb.append(score.getCode()).append(CRT001);
        //查询类型  checkResult
        sb.append(score.getCheckResult()).append(CRT001);
        //状态码    status
        sb.append(score.getStatus()).append(CRT001);
        //百维信用分  score
        sb.append(score.getScore()).append(CRT001);

        key.set(getKey());
        val.set(sb.toString().replace("\n","").replace("\r", " "));
        context.write(key,val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_baiwei_score_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIWEI_SCORE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百维信用分";
    }
}
